package com.zhuiyun.educations.api.homepage.service.impl;

import com.zhuiyun.educations.api.homepage.entity.CourseVo;
import com.zhuiyun.educations.api.homepage.entity.Rotaion;
import com.zhuiyun.educations.api.homepage.mapper.CourseVoMapper;
import com.zhuiyun.educations.api.homepage.service.CourseVoService;
import com.zhuiyun.educations.api.newCourse.entity.CourseUnit;
import com.zhuiyun.educations.api.newCourse.entity.DTO.CourseDTO;
import com.zhuiyun.educations.api.newCourse.entity.UnitJoint;
import com.zhuiyun.educations.common.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName CourseVoServiceImpl
 * @Description TODO
 * @Author yuanb
 * @Date 2023/6/21 11:40
 **/
@Service
public class CourseVoServiceImpl implements CourseVoService {
    @Autowired
    private CourseVoMapper courseVoMapper;
    /**
        * @Author yuanb
        * @Description pc端首页活数据免费数据
        * @Date 2023/6/21 16:19
        * @Return com.zhuiyun.educations.common.response.CommonResult
        *
    */
    @Override
    public CommonResult homePageAllFree() {
           List<CourseVo> list=courseVoMapper.homePageAllFree();
           return CommonResult.ok(list);
    }
    /**
        * @Author yuanb
        * @Description 轮播图
        * @Date 2023/6/21 16:34
        * @Return com.zhuiyun.educations.common.response.CommonResult
        *
    */
    @Override
    public CommonResult CarouselAll(Rotaion rotaion) {
        Rotaion rotaion1 = courseVoMapper.CarouselAll(rotaion);
        return CommonResult.ok(rotaion1);
    }
    /**
     * @Author yuanb
     * @Description pc端首页活数据收费数据
     * @Date 2023/6/21 16:19
     * @Return com.zhuiyun.educations.common.response.CommonResult
     *
     */
    @Override
    public CommonResult homePageAllcharge() {
        List<CourseVo> list=courseVoMapper.homePageAllcharge();
        return CommonResult.ok(list);
    }

    /**
    * @Author MJL
    * @Description todo pc端新课推荐数据
    * @Date 2023/6/27 15:41
    * @Return  * @param null
    */
    @Override
    public CommonResult homePageNewAllCharge() {
        List<CourseVo> list = courseVoMapper.homePageNewAllCharge();
        return CommonResult.ok(list);
    }

    /**
    * @Author MJL
    * @Description todo pc端微专业数据
    * @Date 2023/6/27 20:39
    * @Return  * @param null
    */
    @Override
    public CommonResult homePageMicroAllCharge() {
        List<CourseVo> list = courseVoMapper.homePageMicroAllCharge();
        return CommonResult.ok(list);
    }

    /**
    * @Author MJL
    * @Description todo pc端获取精选课数据
    * @Date 2023/6/28 15:40
    * @Return  * @param null
    */
    @Override
    public CommonResult homePageSelected() {
        List<CourseVo> list = courseVoMapper.homePageSelected();
        return CommonResult.ok(list);
    }

    @Override
    public CommonResult homePageSelectedById(Integer id) {
        return CommonResult.ok(courseVoMapper.homePageSelectedById(id));
    }

    @Override
    public List<CourseUnit> homePageUnitById(Integer id) {
        //根据课程id全查章节
        List<CourseUnit> courseUnits = courseVoMapper.homePageUnitById(id);
        //循环获取每个章节
        for(int c=0;c<courseUnits.size();c++){
            //创建小课对象
            List<UnitJoint> joints=new ArrayList<>();
            //获取章节id
            CourseUnit courseUnit = courseUnits.get(c);
            Integer id1 = courseUnit.getId();
            //根据章节id查小课
            List<UnitJoint> joints1 = courseVoMapper.homePageJointById(id1);
            //获取每个小课
            for(int a=0;a<joints1.size();a++){
                //把每个小课存给子级集合
                joints.add(joints1.get(a));
            }
            //把子级集合的值复制给章节对象
            courseUnits.get(c).setJoints(joints);
            System.out.println("11111111111"+joints);
        }

        return courseUnits;
    }

    @Override
    public  List<UnitJoint> homePageJointById(Integer id) {
        return courseVoMapper.homePageJointById(id);
    }

    /**
    * @Author MJL
    * @Description todo pc端大课程分类
    * @Date 2023/6/29 11:08
    * @Return  * @param null
    */
    @Override
    public CommonResult BigClassList() {
        List<CourseVo> list = courseVoMapper.BigClassList();
        return CommonResult.ok(list);
    }

    /**
    * @Author MJL
    * @Description todo pc端小课程数据
    * @Date 2023/6/29 14:02
    * @Return  * @param null
    */
    @Override
    public CommonResult SmallClassList(Integer subjectId) {
        List<CourseVo> list = courseVoMapper.SmallClassList(subjectId);
        return CommonResult.ok(list);
    }

    @Override
    public CourseDTO selectCourseInfo(Integer id) {
        return courseVoMapper.selectCourseInfo(id);
    }
}

